!function (e, $, mui) {
    "use strict";
	
	var config = {
	};
	// 定义页面
	var p = function(config) {
		var t = this;
		t.config = config;
		t.userInfo = null;
		t.element = {
            start: $('.start'),
            end: $('.end'),
            num: $('.num'),
            start_time: $('.start_time'),
            create_time: $('.create_time'),
            finished_time: $('.finished_time'),
            status: $('.status'),
            driver_name: $('.driver_name'),
            driver_mobile: $('.driver_mobile'),
            driver_location: $('.driver_location'),
            car_no: $('.car_no'),
            action: $('.action'),
            cancel: $('.cancel'),
            finish: $('.finish'),
            driver_container: $('.mui-content-subway')
		};
		t.init();
	};
	
	var pt = p.prototype;
	
	// 页面初始化
	pt.init = function () {
		var t = this;
		t.userInit();
		// 页面初始化
		t.pageLoad();
		// 页面监听
        t.listen();
	};

	pt.listen = function () {
	    var t = this;
        t.element.cancel.on('tap', function () {
            mui.confirm('是否确定取消运单', '温馨提示', ['取消', '确定'], function (res) {
                if(res.index == 0) return;
                // 取消运单
                baseApi.get(
                    'taxi/cancel',
                    {id: getQueryString('id')},
                    function (result) {
                        mui.toast('操作成功');
                        setTimeout(function () {
                            location.reload();
                        }, 500);
                    }
                );

            });
        });

        t.element.finish.on('tap', function () {
            mui.confirm('是否确定完成运单', '温馨提示', ['取消', '确定'], function (res) {
                if(res.index == 0) return;
                // 完成运单
                baseApi.get(
                    'taxi/finish',
                    {id: getQueryString('id')},
                    function (result) {
                        mui.toast('操作成功');
                        setTimeout(function () {
                            location.reload();
                        }, 500);
                    }
                );

            });
        });
    };
	
	// 用户信息初始化
	pt.userInit = function() {
		var t = this;
		t.userInfo = getLocalUserInfo();
	};

    // 页面加载
    pt.pageLoad = function () {
        var t = this;
        baseApi.get(
            'taxi/info',
            {id: getQueryString('id')},
            function (result) {

                // 页面加载
                t.element.start.html(result.start);
                t.element.end.html(result.end);
                t.element.num.html(result.num);
                t.element.start_time.html(result.start_time);
                t.element.create_time.html(result.create_time_format);
                if(result.finished_time_format) {
                    t.element.finished_time.html(result.finished_time_format);
                } else {
                    t.element.finished_time.parent().hide();
                }
                t.element.status.html(result.status_format);

                t.element.action.hide();
                if(result.status == 2 || result.status == 1) {
                    t.element.action.show();
                    if(result.status == 2) {
                        t.element.finish.show();
                    } else {
                        t.element.finish.hide();
                    }
                }

                if(!result.driver_name) {
                    t.element.driver_container.hide();
                } else {
                    t.element.driver_container.show();
                }

                t.element.driver_name.html(result.driver_name);
                t.element.driver_mobile.html(result.driver_mobile);
                t.element.driver_location.data('url', 'https://uri.amap.com/marker?position='+result.start_longitude+','+result.start_latitude);
                t.element.car_no.html(result.car_no);
            }
        );
    }
	
	// 页面初始化
	e.page = new p(config);

}(window, $, mui);